package com.gtw.utils;

import java.io.UnsupportedEncodingException;

/** URL 转码解码
 * Created by wuye on 2018/3/26.
 */
public class UrlUtil {

    private final static String ENCODE = "UTF-8";
    /**
     * URL 解码
     *
     */
    public static String getURLDecoderString(String str) {
        String result = "";
        if (null == str) {
            return "";
        }
        try {
            result = java.net.URLDecoder.decode(str, ENCODE);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return result;
    }
    /**
     * URL 转码
     *
     */
    public static String getURLEncoderString(String str) {
        String result = "";
        if (null == str) {
            return "";
        }
        try {
            result = java.net.URLEncoder.encode(str, ENCODE);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return result;
    }

    /**
     *
     */
    public static void main(String[] args) {
        String str = "http://guangtouboy.com/gtw/api/routin/routing?url=http%3A%2F%2Fwww.guangtouboy.com%2F%23%2FFriendBargain%3FpriceList%3DeyJ0aHJlZWJhcmdhaW4iOjgwLCJ0ZW5iYXJnYWluIjo3MCwic2l4YmFyZ2FpbiI6NjB9%26acid%3D9%26gid%3D9%26aid%3D8%26uid%3D62%26";
        System.out.println(getURLEncoderString(str));
        System.out.println(getURLDecoderString(str));

    }

}
